using System;
using Spring.Data.NHibernate.Support;
using Spring.Data.NHibernate;
using NHibernate; 
using NHibernate.Criterion;
using System.Collections.Generic;
using System.Collections;
 
namespace pos.entity
{
    /// <summary>
    /// Summary description for 历史出库记录 数据库访问类
    /// </summary>
    public partial  class HreturnedDao:Dao<Hreturned>
    {
        
        public struct TReturned
        {
            public string id;
            public double amount;
            public double money;
            
        }
     
        public TReturned GetOutInfo(string id)
        {
            
            dc = DC.Add(Restrictions.Eq("commodityID",id));
            ProjectionList pl = Projections.ProjectionList()
              .Add(Projections.SqlProjection("sum(returnedAmount) as b", new String[] { "b" }, new NHibernate.Type.IType[] { NHibernate.NHibernateUtil.Double }))
              .Add(Projections.SqlProjection("sum(returnedMoney) as a", new String[] { "a" }, new NHibernate.Type.IType[] { NHibernate.NHibernateUtil.Double }));
            Object[] rs =(Object[]) this.uniqueResult(dc.SetProjection(pl));
            TReturned stock = new TReturned();
            stock.id = id;
            if (rs == null)
            {
                stock.amount = 0;
                stock.money = 0;
            }
            else
            {
                stock.amount = Convert.ToDouble(rs[0]);
                stock.money = Convert.ToDouble(rs[1]);
            }
            return stock;
                

            
            
            
        }

    }
}

